package com.google.code.timetrail.gui;

import javax.swing.JFrame;
import javax.swing.JOptionPane;

import com.google.code.timetrail.backend.ConsumptionRate;
import com.google.code.timetrail.backend.Control;
import com.google.code.timetrail.backend.TravelSpeed;


public class RationsPaceFrameBackend {
    private Control gameControl;
    private ConsumptionRate rations;
    private TravelSpeed pace;
    private int selectedRations;
    private int selectedPace;
    private JFrame frame;
    public RationsPaceFrameBackend(Control gameControl){
        this.gameControl = gameControl;
        selectedRations = -1;
        selectedPace = -1;
    }
    public String getPaceLabelText() {

        return "Select Pace: ";
    }
    public String getRationsLabelText() {

        return "Select Rations: ";
    }
    public void rationsListChanged(int selectedIndex) {

        selectedRations = selectedIndex;
        if(selectedIndex == 0){
            rations = ConsumptionRate.NONE;
        } else if(selectedIndex == 1){
            rations = ConsumptionRate.BAREBONES;
        } else if(selectedIndex == 2){
            rations = ConsumptionRate.MEAGER;
        } else if(selectedIndex == 3){
            rations = ConsumptionRate.NORMAL;
        } else if(selectedIndex == 4){
            rations = ConsumptionRate.WELLFED;
        }
        
    }
    public String[] getRationsValues() {

        return new String[] {"None ", "bare-bones ", "Meager ", "Normal", "Wellfed "};
    }
    public void paceValueChanged(int selectedIndex) {
        selectedPace = selectedIndex;
        if(selectedIndex == 0){
            pace = TravelSpeed.STOPPED;
        } else if(selectedIndex == 1){
            pace = TravelSpeed.MACH;
        } else if(selectedIndex == 2){
            pace = TravelSpeed.WARP;
        } else if(selectedIndex == 3){
            pace = TravelSpeed.LUDICROUS;
        }

        
    }
    public String[] getPaceValues() {

        return new String[] {"Stopped", "Mach", "Warp", "Ludacris"};
    }
    public boolean pressNextButton() {
        // TODO link cards
        if(selectedPace == -1 || selectedRations == -1){
            JOptionPane.showMessageDialog(frame,
                    "Please fill in all required information.",
                    "Some fields were left empty",
                    JOptionPane.PLAIN_MESSAGE);
            return false;
        } else {
            
            
            gameControl.setPace(pace);
            gameControl.setRations(rations);
            return true;

        }
        
    }
    public String getNextButtonText() {

        return "Next >>";
    }
    public String getBackButtonText() {

        return "Back <<";
    }
    public void pressBackButton() {
        // TODO link cards
        
    }
}
